'''
Created on Jan 19, 2010

@author: christianp
'''
import unittest
from BruTile.Extent import Extent

class UExtent(unittest.TestCase):
    
    extent1 = Extent(0,0,50,50)
    extent2 = Extent(0.5,0.5,50.5,50.5)
    other1 = Extent(10,10,60,60)
    other2 = Extent(60.5,60.5,80.5,80.5)
    
    def test_getters_setters (self):
        print("UExtent: test_getters_setters")
        self.assertEqual(self.extent1.get_min_x(), 0, "extent1.get_min_x()")
        self.assertEqual(self.extent1.get_min_y(), 0, "extent1.get_min_y()")
        self.assertEqual(self.extent1.get_max_x(), 50, "extent1.get_max_x()")
        self.assertEqual(self.extent1.get_max_y(), 50, "extent1.get_max_y()")
        self.assertEqual(self.extent1.get_center_x(), 25, "self.extent1.get_center_x()")
        self.assertEqual(self.extent1.get_center_y(), 25, "self.extent1.get_center_y()")
        self.assertEqual(self.extent2.get_center_x(), 25.5, "self.extent2.get_center_x()")
        self.assertEqual(self.extent2.get_center_y(), 25.5, "self.extent2.get_center_y()")
        self.assertEqual(self.extent1.get_width(), 50, "self.extent1.get_width()")
        self.assertEqual(self.extent1.get_height(), 50, "self.extent1.get_height()")
        self.assertEqual(self.extent2.get_width(), 50, "self.extent2.get_width()")
        self.assertEqual(self.extent2.get_height(), 50, "self.extent2.get_height()")
        
    def test_area(self):
        print("UExtent: test_area")
        self.assertEqual(self.extent1.get_area(), 2500, "self.extent1.get_height()")
    
    def test_intersects_with_is_intersecting(self):
        print("UExtent: test_intersects_with_is_intersecting")
        temp_extent = self.extent1.intersects_with(self.other1)
        
        self.assertEqual(temp_extent.get_min_x(), 10, "temp_extent.get_min_x()")
        self.assertEqual(temp_extent.get_min_y(), 10, "temp_extent.get_min_y()")
        self.assertEqual(temp_extent.get_max_x(), 50, "temp_extent.get_max_x()")
        self.assertEqual(temp_extent.get_max_y(), 50, "temp_extent.get_max_y()")
        
        self.assertEqual(self.extent1.is_intersecting(self.other1), True, "def is_intersecting (self, box):")
        self.assertRaises(Exception, self.extent2.intersects_with, self.other2)
        self.assertEqual(self.extent1.is_intersecting(self.other2), False, "def is_intersecting (self, box):")

if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    unittest.main()